home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / ITOA.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  2KB  |  118 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ; Modifications for Release 2.0:
  9. ;
  10. ; Created separate routines for malloc'd and non-malloc'd versions.  The
  11. ; malloc'd versions appear in a separate file.
  12. ;
  13. ; Added ITOA2/UTOA2 which do not preserve DI for use when building strings
  14. ; of data from various calls.
  15. ;
  16. ; 9/22/91.  Randy Hyde
  17. ;
  18. ;----------------------------------------------------------------------------
  19. ;
  20. ; ITOA-    Converts the signed integer value in AX to a string of characters.
  21. ;    ES:DI must point at an array big enough to hold the result (7 chars
  22. ;    max.).
  23. ;
  24. ; ITOA2-Does not preserve DI.  Returns with DI pointing at the zero
  25. ;    terminating byte.
  26. ;
  27. ;
  28. ;
  29. ;
  30.         public    sl_itoa
  31. sl_itoa        proc    far
  32.         push    di
  33.         call    far ptr sl_itoa2
  34.         pop    di
  35.         ret
  36. sl_itoa        endp
  37. ;
  38.         public    sl_itoa2
  39. sl_itoa2    proc    far
  40.         push    ax
  41.         push    bx
  42.         push    dx
  43. ;
  44. ; If it's negative, output the sign.
  45. ;
  46.         cmp    ax, 0
  47.         jge    Doit
  48.         mov    byte ptr es:[di], '-'
  49.         inc    di
  50.         neg    ax
  51. ;
  52. ; Output the number:
  53. ;
  54. DoIt:        call    puti2
  55.         mov    byte ptr es:[di], 0
  56.         clc                ;Needed by sl_itoam
  57.         pop    dx
  58.         pop    bx
  59.         pop    ax
  60.         ret
  61. sl_itoa2    endp
  62. ;
  63. ;
  64. ; UTOA- Converts unsigned value in AX to a string of digits and stores
  65. ;    this string starting at the location pointed at by ES:DI.  Since
  66. ;    the maximum 16-bit unsigned value is 65535, this routine may store
  67. ;    up to six bytes at ES:DI (5 digits plus a zero byte).
  68. ;
  69. ; UTOA2-Like the routine above, except this one does not preserve the DI
  70. ;    register.  It returns DI pointing at the zero byte.
  71. ;
  72. ;
  73.         public    sl_utoa
  74. sl_utoa        proc    far
  75.         push    di
  76.         call    far ptr sl_utoa2
  77.         pop    di
  78.         ret
  79. sl_utoa        endp
  80. ;
  81.         public    sl_utoa2
  82. sl_utoa2    proc    far
  83.         push    ax
  84.         push    bx
  85.         push    dx
  86.         call    PutI2
  87.         mov    byte ptr es:[di], 0
  88.         clc                ;Needed by sl_utoam
  89.         pop    dx
  90.         pop    bx
  91.         pop    ax
  92.         ret
  93. sl_utoa2    endp
  94. ;
  95. ;
  96. ;
  97. ; PutI2- Recursive routine to actually print the value in AX as an integer.
  98. ;
  99.         public    Puti2
  100. Puti2        proc    near
  101.         mov    bx, 10
  102.         xor    dx, dx
  103.         div    bx
  104.         or    ax, ax        ;See if ax=0
  105.         jz    Done
  106.         push    dx
  107.         call    Puti2
  108.         pop    dx
  109. Done:        mov    al, dl
  110.         or    al, '0'
  111.         mov    es:[di], al
  112.         inc    di
  113.         ret
  114. PutI2        endp
  115. ;
  116. stdlib        ends
  117.         end
  118.